import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Vector;


public class SocketThreadForWholeDrawing extends Thread{
	
	String hostName;
    int portNumber;
    Socket connectionToReceiver;
    Vector<PointDrawn> Changes;
    String UniqueStringofTabChanged;
    String tabTitle;
    
    public SocketThreadForWholeDrawing(String hostName, int portNumber, String StringofTabChanged, String tabTitle, Vector<PointDrawn> Changes) {
            this.hostName = hostName;
            this.portNumber = portNumber;
            this.Changes = Changes;
            this.UniqueStringofTabChanged = StringofTabChanged;
            this.tabTitle = tabTitle;
    }
    
    public void run() {
            try {
                    connectionToReceiver = new Socket(hostName, portNumber);
                    if(connectionToReceiver == null){
                    	System.out.println("Null Connectoin in STFWD");
                    	return;
                    }
                    DataOutputStream dos = new DataOutputStream(connectionToReceiver.getOutputStream());
                    dos.writeInt(9);
                    dos.writeUTF(UniqueStringofTabChanged);
                    dos.writeUTF(tabTitle);
                    //Going to change this to a unique string that gets
                    //changed
                    dos.writeInt(Changes.size());
                    System.out.println("before for");
                    for(int c = 0; c < Changes.size(); c++) {
                            PointDrawn CurChange = Changes.get(c);
                            dos.writeInt(CurChange.x1);
                            dos.writeInt(CurChange.y1);
                            dos.writeInt(CurChange.radius);
                            dos.writeInt(CurChange.clr.getRGB());
                            int FakeBool;
                            if(CurChange.draw) {
                                    FakeBool = 1;
                            } else {
                                    FakeBool = 2;
                            }
                            dos.writeInt(FakeBool);
                            
                            if(c == Changes.size()-1) {
                                    System.out.println("xyr  "  + CurChange.x1 + "  "+ CurChange.y1 + "  "+ CurChange.radius); 
                            }
                    }
                   connectionToReceiver.close();
            } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    System.out.println("Error Error Error");
            }
            
    }
}
